package org.jeecg.modules.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.flowable.common.util.validation.MustParamValidation;
import org.jeecg.modules.flowable.service.FlowProcService;
import org.jeecg.modules.flowable.service.bo.taskdetail.TaskBrowseDetailFormData;
import org.jeecg.modules.flowable.service.bo.taskdetail.TaskDetail;
import org.jeecg.modules.flowable.system.core.SystemUser;
import org.jeecg.modules.flowable.system.etc.SystemUserUtil;
import org.jeecg.modules.flowable.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * Title:  <br>
 * Desc:  <br>
 * Date: 6/17/22 5:44 PM <br>
 * Company: 联通（辽宁）产业互联网有限公司 <br>
 *
 * @author zxd
 * @version 1.0.0
 */
@Api(value = "FlowableProcController", tags = {"(module-flowable)-流程处理"})
@ApiSort(value = 1)
@RestController
@RequestMapping("/FlowableProcController")
@Slf4j
public class FlowableProcController {

    @Autowired
    private FlowProcService flowProcService;

    @ApiOperation(value = "我待办的流程", notes = "我待办的流程")
    @RequestMapping(path = "/queryMyTodoByPage", method = RequestMethod.POST)
    @ResponseBody
    public Result<Page<Map<String, Object>>> queryMyTodoByPage(@RequestParam("pageNo") Integer argCurrPage, @RequestParam("pageSize") Integer argPageSize) {
        MustParamValidation.mustValidation(argCurrPage, argPageSize);
        SystemUser loginUser = SystemUserUtil.getSystemUser();
        Page<Map<String, Object>> mapPage = flowProcService.queryMyTodoByPage(loginUser.getId(), argCurrPage, argPageSize);
        return Result.OK(mapPage);
    }

    @ApiOperation(value = "我发起的流程", notes = "我发起的流程")
    @RequestMapping(path = "/queryMyFlow", method = RequestMethod.POST)
    @ResponseBody
    public Result<Page<Map<String, Object>>> queryMyFlow(@RequestParam("pageNo") Integer argCurrPage, @RequestParam("pageSize") Integer argPageSize) {
        MustParamValidation.mustValidation(argCurrPage, argPageSize);
        SystemUser loginUser = SystemUserUtil.getSystemUser();
        Page<Map<String, Object>> mapPage = flowProcService.queryMyFlow(loginUser.getId(), argCurrPage, argPageSize);
        return Result.OK(mapPage);
    }

    @ApiOperation(value = "我处理的流程", notes = "我处理的流程")
    @RequestMapping(path = "/queryMyProc", method = RequestMethod.POST)
    @ResponseBody
    public Result<Page<Map<String, Object>>> queryMyProc(@RequestParam("pageNo") Integer argCurrPage, @RequestParam("pageSize") Integer argPageSize) {
        MustParamValidation.mustValidation(argCurrPage, argPageSize);
        SystemUser loginUser = SystemUserUtil.getSystemUser();
        Page<Map<String, Object>> mapPage = flowProcService.queryMyProc(loginUser.getId(), argCurrPage, argPageSize);
        return Result.OK(mapPage);
    }

    @ApiOperation(value = "我的草稿", notes = "我的草稿")
    @RequestMapping(path = "/queryMyDraft", method = RequestMethod.POST)
    @ResponseBody
    public Result<Page<Map<String, Object>>> queryMyDraft(@RequestParam("pageNo") Integer argCurrPage, @RequestParam("pageSize") Integer argPageSize) {
        MustParamValidation.mustValidation(argCurrPage, argPageSize);
        SystemUser loginUser = SystemUserUtil.getSystemUser();
        Page<Map<String, Object>> mapPage = flowProcService.queryMyDraft(loginUser.getId(), argCurrPage, argPageSize);
        return Result.OK(mapPage);
    }

    @ApiOperation(value = "任务详情信息", notes = "任务详情信息(只有待办任务列表传递TASKID参数，其它列表不传)")
    @RequestMapping(path = "/queryTaskDetail", method = RequestMethod.POST)
    @ResponseBody
    public Result<TaskDetail> queryTaskDetail(String argMatterInstId, String argTaskId) {
        TaskDetail taskDetail = flowProcService.queryTaskDetail(argMatterInstId, argTaskId, false, true);
        return Result.OK(taskDetail);
    }

    @ApiOperation(value = "任务详情信息", notes = "任务详情信息")
    @RequestMapping(path = "/detail4Biz/{argMatterInstId}", method = RequestMethod.GET)
    @ResponseBody
    public Result<?> detail(@PathVariable String argMatterInstId) {
        TaskDetail taskDetail = flowProcService.queryTaskDetail(argMatterInstId, null, true, true);
        return Result.OK(taskDetail);
    }

    @ApiOperation(value = "查询任务过程中自定义表单和附件数据", notes = "查询任务过程中自定义表单和附件数据")
    @RequestMapping(path = "/queryTaskFormData", method = RequestMethod.POST)
    @ResponseBody
    public Result<TaskBrowseDetailFormData> queryTaskFormData(String argActRuActinstId) {
        TaskBrowseDetailFormData taskBrowseDetailFormData = flowProcService.queryTaskFormData(argActRuActinstId);
        return Result.OK(taskBrowseDetailFormData);
    }

}